<div class="widget-head" style="margin-top:0;">
    <div class="widget-title">配置积分规则</div>
</div>
<div class="layui-container" style="width:100%;">
    <div class="layui-clear">
        <a class="layui-btn fl" onclick="think_open('/admin/config/jifen_edit','添加积分规则',['60%','60%'],0)">添加</a>

        <a class="layui-btn layui-btn-danger think-btn fl" data-type="del" data-url="/api/jifen/del">批量删除</a>
        <form method="GET" action="{:U('jifen')}" class="fr layui-form" style="width:400px;">
            <div class="layui-input-inline fl" style="width:100px;">
                <php>$types = ['skey'=>'积分key','text'=>'积分规则'];</php>
                <select name="searchtype">
                    <foreach name="types" item="vo" key="k">
                        <option value="{$k}" <if condition="$_GET['searchtype'] eq $k">selected</if>>{$vo}</option>
                    </foreach>
                </select>
            </div>
            <div class="layui-input-inline fr" style="width:300px;">
                <button class="layui-btn fr" lay-submit>搜索</button>
                <input type="text" class="layui-input fr" style="width:230px;" name="keywords" placeholder="请输入关键词" value="{$_GET['keywords']}">
            </div>
            <?php
                $condition = [];
                if($_GET['searchtype'] && $_GET['keywords']){
                    $condition['searchtype'] = $_GET['searchtype'];
                    $condition['keywords'] = $_GET['keywords'];
                }
            ?>
                <script>
                    var condition = eval('({:json_encode($condition,JSON_UNESCAPED_UNICODE)})');
                </script>
        </form>
    </div>
    <table id="list"></table>
    <script type="text/html" id="barDemo">
        <div class="layui-btn-group action-btn">
            <a class="layui-btn layui-btn-xs" href="javascript:think_open('/admin/config/jifen_edit/id/{{d.id}}','修改积分规则',['60%','60%'],0);">修改</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs mini_del" data-url="/api/jifen/del/ids/{{d.id}}">删除</a>
        </div>
    </script>
    <script type="text/html" id="statusTpl">
        {{# if(d.status == '1' ){ }}
        <span class="layui-badge layui-bg-green">正常</span> {{# }else if(d.status == '-1'){ }}
        <span class="layui-badge layui-bg-red">禁用</span> {{# }else{ }}
        <span class="layui-badge layui-bg-gray">未知</span> {{# } }}
    </script>
</div>
<script>
    layui.use(['think'], function() {
        var think = layui.think;
        //第一个实例
        think.render({
            elem: '#list',
            // height: 500,
            url: '/api/jifen/getdata',
            method: 'post',
            where: condition,
            page: true,
            toolbar: true,
            cols: [
                [ //表头
                    {
                        type: 'checkbox',
                        fixed: 'left'
                    }, {
                        field: 'id',
                        title: 'ID',
                        width: 50,
                    }, {
                        field: 'skey',
                        title: '积分KEY'
                    }, {
                        field: 'text',
                        title: '积分规则',
                    }, {
                        field: 'status',
                        title: '状态',
                        width: 80,
                        templet: '#statusTpl'
                    }, {
                        field: 'update_time',
                        title: '修改时间',
                        width: 177,
                        sort: true,
                        templet: function(d) {
                            return think_time(d.update_time, 'Y-m-d H:i:s'); //think_time()是think.js里面的方法
                        }
                    }, {
                        title: '操作',
                        width: 150,
                        align: 'center',
                        toolbar: '#barDemo'
                    }
                ]
            ]
        }, '{$_GET["searchtype"]}', '{$_GET["keywords"]}');
    });
</script>